package com.theydream.qeechain.main;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.theydream.qeechain.R;
import com.theydream.qeechain.facebook.FacebookConnector;
import com.theydream.qeechain.facebook.SessionEvents;
import com.theydream.qeechain.globaldata.CaughtItemListClass;
import com.theydream.qeechain.globaldata.GlobalData;
import com.theydream.qeechain.globaldata.definition.CaughtPet;
import com.theydream.qeechain.loading.StartingScreen2R;

public class BossPage extends Activity {
	private int bossImage[]={R.drawable.unlock_boss,R.drawable.collect12	
	};

	ImageView mainImage;
	ImageView imageFinish;
	ImageView rightArrow;
	ImageView leftArrow;
	ImageView itemList;
	ImageView btnReturn;

	private int slide=0;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.boss);
		mainImage=(ImageView)findViewById(R.id.boss_image);
		imageFinish=(ImageView)findViewById(R.id.boss_finish);
		itemList=(ImageView)findViewById(R.id.btn_itemlist);
		btnReturn=(ImageView)findViewById(R.id.btn_return);
		rightArrow=(ImageView)findViewById(R.id.boss_right_arrow);
		leftArrow=(ImageView)findViewById(R.id.boss_left_arrow);
		imageFinish.setVisibility(ImageView.INVISIBLE);
		mainImage.setImageResource(bossImage[slide]);
		String PREF_NAME= "IsFirstGame";
		SharedPreferences prefSetting=getSharedPreferences(PREF_NAME,MODE_PRIVATE);
		if (prefSetting.getBoolean("FirstGame", true))
		{
			itemList.setVisibility(ImageView.INVISIBLE);
			btnReturn.setVisibility(ImageView.INVISIBLE);
		}
		
	}
	
	public void clickLeftArrow(View target)
	{
		if (slide==bossImage.length-1)
		{
			mainImage.setImageResource(bossImage[--slide]);
			imageFinish.setVisibility(ImageView.INVISIBLE);
			rightArrow.setVisibility(ImageView.VISIBLE);
		}
		if (slide>0)
		{
			mainImage.setImageResource(bossImage[--slide]);
		}
		
		
	}
	public void clickRightArrow(View target)
	{
		if (slide<bossImage.length-2)
		{
			mainImage.setImageResource(bossImage[++slide]);
		}
		else if (slide<bossImage.length-1)
		{
			mainImage.setImageResource(bossImage[++slide]);
			imageFinish.setVisibility(ImageView.VISIBLE);
			rightArrow.setVisibility(ImageView.INVISIBLE);
			imageFinish.setVisibility(ImageView.VISIBLE);
			leftArrow.setVisibility(ImageView.INVISIBLE);
		}
	}
	public void clickFinish(View target)
	{
		String PREF_NAME= "IsFirstGame";
		SharedPreferences prefSetting=getSharedPreferences(PREF_NAME,MODE_PRIVATE);
		if (prefSetting.getBoolean("FirstGame", true))
		{
			startActivity(new Intent(this,Tutorial.class));
		}
		else
		this.finish();
	}
	public void toItemList(View target)
	{
		Intent intent=new Intent(this,ItemCollected.class);
		startActivity(intent);
		this.finish();
	}
	public void returnPage (View target)
	{
		this.finish();
	}
}
		
//		ImageView petImage = (ImageView) findViewById(R.id.pet_image);
//		TextView petName = (TextView) findViewById(R.id.pet_name);
//		TextView petDesc = (TextView) findViewById(R.id.pet_desc);
//		TextView petTime = (TextView) findViewById(R.id.caught_time);
//		TextView petS = (TextView) findViewById(R.id.strength);
//		TextView petP = (TextView) findViewById(R.id.perception);
//		TextView petE = (TextView) findViewById(R.id.endurance);
//		TextView petC = (TextView) findViewById(R.id.charisma);
//		TextView petI = (TextView) findViewById(R.id.intelligence);
//		TextView petA = (TextView) findViewById(R.id.agility);
//		TextView petL = (TextView) findViewById(R.id.luck);
//		TextView petAddress = (TextView) findViewById(R.id.caught_address);
//		
//		// ===========================================
//		// | Bind infomation to view
//		// ===========================================
//		if (bundle != null) {
//			CaughtPet mPet = CaughtItemListClass.getInstance()
//					.getItemList().get(bundle.getInt("id"));
//
//			// get drawable resource by name
//			petImage.setImageResource(getResources().getIdentifier(
//					mPet.getPet().getPic(), "drawable",
//					this.getPackageName()));
//
//			GlobalData.getInstance().setCaughtPetImage(
//					getResources().getIdentifier(mPet.getPet().getPic(),
//							"drawable", this.getPackageName()));
//
//			petName.setText(mPet.getPet().getName());
//			petTime.setText(mPet.getTime());
//			petDesc.setText(mPet.getPet().getDesc());
//
//			Map<String, Integer> map = mPet.getPet().getAttr();
//			petS.setText(map.get("S").toString());
//			petP.setText(map.get("P").toString());
//			petE.setText(map.get("E").toString());
//			petC.setText(map.get("C").toString());
//			petI.setText(map.get("I").toString());
//			petA.setText(map.get("A").toString());
//			petL.setText(map.get("L").toString());
//
//			// ===========================================
//			// | Location to Address
//			// ===========================================
//			Location location = new Location("Caught Location");
//			location.setLatitude(Double.valueOf(mPet.getLat()));
//			location.setLongitude(Double.valueOf(mPet.getLng()));
//			double geoLatitude = location.getLatitude() * 1E6;
//			double geoLongitude = location.getLongitude() * 1E6;
//			GeoPoint gp = new GeoPoint((int) geoLatitude,
//					(int) geoLongitude);
//
//			Geocoder gc = new Geocoder(this, Locale.CHINA);
//
//			double Latitude = (int) gp.getLatitudeE6() / 1E6;
//			double Longitude = (int) gp.getLongitudeE6() / 1E6;
//
//			List<Address> lstAddress;
//			try {
//				lstAddress = gc.getFromLocation(Latitude, Longitude, 1);
//				if (lstAddress.size() > 0) {
//					Address mAddress = lstAddress.get(0);
//					petAddress.setText(mAddress.getAddressLine(1)
//							.toString());
//				}
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//
//	}
		
	

	

